package com.ruoyi.chiwen.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.chiwen.domain.TbAudit;
import com.ruoyi.chiwen.service.ITbAuditService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 审核Controller
 * 
 * @author chiwen
 * @date 2021-06-14
 */
@RestController
@RequestMapping("/chiwen/audit")
public class TbAuditController extends BaseController
{
    @Autowired
    private ITbAuditService tbAuditService;

    /**
     * 查询审核列表
     */
    @PreAuthorize("@ss.hasPermi('chiwen:audit:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbAudit tbAudit)
    {
        startPage();
        List<TbAudit> list = tbAuditService.selectTbAuditList(tbAudit);
        return getDataTable(list);
    }

    /**
     * 导出审核列表
     */
    @PreAuthorize("@ss.hasPermi('chiwen:audit:export')")
    @Log(title = "审核", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TbAudit tbAudit)
    {
        List<TbAudit> list = tbAuditService.selectTbAuditList(tbAudit);
        ExcelUtil<TbAudit> util = new ExcelUtil<TbAudit>(TbAudit.class);
        return util.exportExcel(list, "审核数据");
    }

    /**
     * 获取审核详细信息
     */
    @PreAuthorize("@ss.hasPermi('chiwen:audit:query')")
    @GetMapping(value = "/{aId}")
    public AjaxResult getInfo(@PathVariable("aId") Long aId)
    {
        return AjaxResult.success(tbAuditService.selectTbAuditById(aId));
    }

    /**
     * 新增审核
     */
    @PreAuthorize("@ss.hasPermi('chiwen:audit:add')")
    @Log(title = "审核", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbAudit tbAudit)
    {
        return toAjax(tbAuditService.insertTbAudit(tbAudit));
    }

    /**
     * 修改审核
     */
    @PreAuthorize("@ss.hasPermi('chiwen:audit:edit')")
    @Log(title = "审核", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbAudit tbAudit)
    {
        return toAjax(tbAuditService.updateTbAudit(tbAudit));
    }

    /**
     * 删除审核
     */
    @PreAuthorize("@ss.hasPermi('chiwen:audit:remove')")
    @Log(title = "审核", businessType = BusinessType.DELETE)
	@DeleteMapping("/{aIds}")
    public AjaxResult remove(@PathVariable Long[] aIds)
    {
        return toAjax(tbAuditService.deleteTbAuditByIds(aIds));
    }
}
